package o;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import BaseDialog.a;
import o.cof.d;
import o.ewm.n;

class dki {
    dki() {
    }

    protected static void ˊ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        int parseInt;
        int i = 0;
        try {
            parseInt = Integer.parseInt(baseDistCardBean.ˎˎ());
        } catch (NumberFormatException e) {
            Logger.e("InstallAppUtil", "versionCode error");
            parseInt = i;
        }
        if (!((ceq) cdb.ॱ(ceq.class)).ˊ(context, baseDistCardBean.ॱـ(), parseInt)) {
            ((cdf) cdb.ॱ(cdf.class)).ॱ(baseDistCardBean.ॱـ());
            downloadButton.ॱ();
        } else if (!((ceq) cdb.ॱ(ceq.class)).ˋ(context, baseDistCardBean.ˉ())) {
            ॱ(downloadButton, baseDistCardBean);
        } else if ((baseDistCardBean instanceof DetailHiddenBean) && 1 == ((DetailHiddenBean) baseDistCardBean).ॱ()) {
            dsl.ˊ(baseDistCardBean.ॱـ(), baseDistCardBean.v_(), baseDistCardBean.ॱˌ(), 1, coc.NORMAL);
        } else {
            ApkUpgradeInfo ॱ = dug.ॱ(baseDistCardBean.ॱـ());
            if (ॱ != null && 1 == ॱ.ˏॱ()) {
                duc.ˎ(downloadButton.getContext(), ॱ.ᐝ(), ॱ.ˊ(), ॱ.ॱᐝ());
            } else if (ॱ == null || 1 != ॱ.ॱˋ()) {
                ˏ(downloadButton.getContext(), baseDistCardBean, o_cke);
            } else {
                duc.ˎ(downloadButton.getContext(), ॱ.ᐝ(), ॱ.ˊ(), ॱ.ॱᐝ(), true);
            }
        }
    }

    private static void ॱ(DownloadButton downloadButton, BaseDistCardBean baseDistCardBean) {
        epj o_epj = new epj();
        o_epj.ˋ(ContentManager.getInstant().getContext().getString(n.ʻᐨ));
        o_epj.ˏ(ContentManager.getInstant().getContext().getString(n.ʻᐧ, new Object[]{baseDistCardBean.v_()}));
        o_epj.ॱ(downloadButton.getContext().getResources().getString(n.ʹᐝ));
        o_epj.ˎ(downloadButton.getContext().getResources().getString(n.ʻˑ));
        ewg.ॱ(downloadButton.getContext(), o_epj, cjl.ˋ("installmgr.activity"), false, "InstallNoSpace");
    }

    private static void ˏ(Context context, BaseCardBean baseCardBean, cke o_cke) {
        dsl.ˊ(baseCardBean.ॱـ(), baseCardBean.v_(), baseCardBean.ॱˌ(), 0, coc.NORMAL);
        dss.ॱ().ˏ(context, czt.TYPE_INSTALL_BUTTON, o_cke);
    }

    protected static boolean ˎ(Context context, final BaseDistCardBean baseDistCardBean) {
        boolean z;
        NameNotFoundException e;
        Exception e2;
        String ॱـ = baseDistCardBean.ॱـ();
        int i = -1;
        try {
            i = Integer.parseInt(baseDistCardBean.ˎˎ());
        } catch (NumberFormatException e3) {
            Logger.ˏ("InstallAppUtil", "NumberFormatException on installExistingApp()!");
        }
        try {
            if (context.getPackageManager().getPackageInfo(ॱـ, 8192).versionCode <= i) {
                return false;
            }
            z = true;
            try {
                BaseAlertDialog ˋ = BaseAlertDialog.ˋ(context, null, context.getString(n.ꞌˋ));
                ˋ.ˎ(new cks() {
                    public void enableNetworking() {
                        int i = 0;
                        int ˏ = etn.ˏ(i);
                        fhz ˋ = fho.ˏ().ˋ("PackageManager");
                        if (ˋ != null) {
                            cnw o_cnw = (cnw) ˋ.ॱ(cnw.class);
                            if (o_cnw != null) {
                                try {
                                    i = Integer.parseInt(baseDistCardBean.ˎˎ());
                                } catch (NumberFormatException e) {
                                    Logger.ˋ("InstallAppUtil", "can not parse versioncode");
                                }
                                o_cnw.ˏ(ContentManager.getInstant().getContext(), new d().ˋ(baseDistCardBean.ॱـ()).ˏ(i).ˊ(ˏ).ॱ(dwq.ˊ).ˎ());
                                return;
                            }
                            Logger.e("InstallAppUtil", "can not found IPackageInstaller Api");
                            return;
                        }
                        Logger.e("InstallAppUtil", "can not found PackageManager module");
                    }

                    public void upgrade() {
                    }

                    public void ˋ() {
                    }
                });
                ˋ.ॱ();
                ˋ.ॱ(a.CONFIRM, n.ˆ);
                return true;
            } catch (NameNotFoundException e4) {
                e = e4;
            } catch (Exception e5) {
                e2 = e5;
                Logger.e("InstallAppUtil", "Exception e: " + e2.toString());
                return z;
            }
        } catch (NameNotFoundException e6) {
            NameNotFoundException nameNotFoundException = e6;
            z = false;
            e = nameNotFoundException;
            Logger.e("InstallAppUtil", "do not find pkg: " + ॱـ + ", e:" + e.toString());
            return z;
        } catch (Exception e7) {
            Exception exception = e7;
            z = false;
            e2 = exception;
            Logger.e("InstallAppUtil", "Exception e: " + e2.toString());
            return z;
        }
    }
}
